<?php

class AccountInfoController extends Controller
{
    private $model;
    function __construct()
    {
        $this->loadLibrary('Utility');
        $this->loadLibrary('Session');
        $this->model = $this->loadModel('accountinfo');
        parent::__construct();
    }

    public function index()
    {
        $id = (isset($_POST['id'])) ? $_POST['id'] : null;
        if ($id != null)
        {
            $username = (isset($_POST['username'])) ? $_POST['username'] : null;
            $password = (isset($_POST['password'])) ? $_POST['password'] : null;
            $repassword = (isset($_POST['repassword'])) ? $_POST['repassword'] : null;

            $message = $this->model->save($id, $username, $password, $repassword);
        }

        $accountInfo = $this->model->getAccountInfo();

        $view = $this->loadView('accountinfo');
        $view->appendBlockData(array('accountInfo'=>$accountInfo));
        if (isset($message))
            $view->appendBlockData(array('message'=>$message));
        $view->setBlockData("Sủa thông tin tài khoản","main_header");
        $view->render();
    }
}

